package cn.jimjim.framework.code.generator;

import cn.hutool.core.util.StrUtil;
import org.jooq.codegen.DefaultGeneratorStrategy;
import org.jooq.meta.Definition;

/**
 * @author jim
 * @date 2019-03-12
 */
public class JooqGeneratorStrategy extends DefaultGeneratorStrategy {

    @Override
    public String getJavaPackageName(Definition definition, Mode mode) {
        if (mode == Mode.RECORD) {
            return super.getJavaPackageName(definition, mode).replace("tables.records", "jooq.tables.records") ;
        }
        String tables = "tables";
        if (!StrUtil.endWith(super.getJavaPackageName(definition, mode), tables)) {
            return super.getJavaPackageName(definition, mode) + ".jooq";
        }
        return super.getJavaPackageName(definition, mode).replace(tables, "jooq.tables");
    }
}
